package cn.stylefeng.guns.modular.agv.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.agv.entity.TaskPassagewayAgvHk;
import cn.stylefeng.guns.modular.agv.mapper.TaskPassagewayAgvHkMapper;
import cn.stylefeng.guns.modular.agv.model.params.TaskPassagewayAgvHkParam;
import cn.stylefeng.guns.modular.agv.model.result.TaskPassagewayAgvHkResult;
import  cn.stylefeng.guns.modular.agv.service.TaskPassagewayAgvHkService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 海康AGV行道管理 服务实现类
 * </p>
 *
 * @author zhangzh
 * @since 2024-05-16
 */
@Service
public class TaskPassagewayAgvHkServiceImpl extends ServiceImpl<TaskPassagewayAgvHkMapper, TaskPassagewayAgvHk> implements TaskPassagewayAgvHkService {

    @Override
    public void add(TaskPassagewayAgvHkParam param){
        TaskPassagewayAgvHk entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaskPassagewayAgvHkParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaskPassagewayAgvHkParam param){
        TaskPassagewayAgvHk oldEntity = getOldEntity(param);
        TaskPassagewayAgvHk newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaskPassagewayAgvHkResult findBySpec(TaskPassagewayAgvHkParam param){
        return null;
    }

    @Override
    public List<TaskPassagewayAgvHkResult> findListBySpec(TaskPassagewayAgvHkParam param){
        return this.baseMapper.customList(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaskPassagewayAgvHkParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TaskPassagewayAgvHkParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaskPassagewayAgvHk getOldEntity(TaskPassagewayAgvHkParam param) {
        return this.getById(getKey(param));
    }

    private TaskPassagewayAgvHk getEntity(TaskPassagewayAgvHkParam param) {
        TaskPassagewayAgvHk entity = new TaskPassagewayAgvHk();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
